import Vue from 'vue'
import App from './App.vue'
import {
  registerApplication,
  start
} from 'single-spa';
import router from './router' //引入路由

async function loadScript(url) {
  return new Promise((resolve,reject)=>{
    let script = document.createElement('script');
    script.src = url;
    script.onload = resolve;
    script.onerror = reject;
    document.head.appendChild(script);
  })
}

// 注册子应用
registerApplication(
  'myVueApp',
  async () => {
    // console.log('加载子vue应用');
    await loadScript(`http://localhost:10000/js/chunk-vendors.js`)
    await loadScript(`http://localhost:10000/js/app.js`)
    
    return window.singleVue;
  },
  location => location.pathname.startsWith('/vue'),  // 用户切换到/vue开头的路径下，我需要加载刚刚定义的子应用
)
start();
// Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App),
}).$mount('#app')
